/************************************************************************

								Heroes IV
					  Copyright 2002, The 3DO Company

	------------------------------------------------------------------
  						 combat_area_shader_data.cpp

	$Header:  $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "combat_area_shader_data.h"

#include "battlefield_metrics.h"

t_map_rect_2d const t_combat_area_shader_data::k_empty_rect( -1, -1, -1, -1 );

t_combat_area_shader_data::t_combat_area_shader_data( int battlefield_size )
	: m_bounding_rect( k_empty_rect ), 
	  m_tile_data( battlefield_size, k_battlefield_cell_height, k_battlefield_logical_view_size, 0 )
{
	m_palette.push_back( 0 ); // Initial "transparent" entry
}


void t_combat_area_shader_data::set_tile_to_color( t_map_point_2d const & point, t_uint8 palette_index )
{
	assert( m_tile_data.is_valid( point ) );
	assert( palette_index < m_palette.size() );
	m_tile_data.get( point ) = palette_index;

	t_map_rect_2d point_as_rect( point, point + t_map_point_2d( 1, 1 ) );
	if ( m_bounding_rect == k_empty_rect )
	{
		m_bounding_rect = point_as_rect;
	}
	else
	{
		m_bounding_rect.merge( point_as_rect );
	}
}



void t_combat_area_shader_data::reset()
{
	m_bounding_rect = k_empty_rect;
	m_palette.clear();
	m_palette.push_back( 0 ); // Initial "transparent" entry

	t_map_point_2d point;

	for ( point.row = 0; point.row < m_tile_data.get_size(); point.row++ )
	{
		for ( point.column = 0; point.column < m_tile_data.get_size(); point.column++ )
		{
			if ( m_tile_data.is_valid( point ) )
				m_tile_data.get( point ) = 0;
		}
	}
}

